package com.dw.controll;

import java.io.IOException;
import java.util.List;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.dw.dao.CriteriaStudent;
import com.dw.dao.StudentDao;
import com.dw.dao.impl.StudentDaoImpl;
import com.dw.model.Student;;

/**
 * Servlet implementation class QueryServlet
 */
public class QueryServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
    private StudentDao StudentDao=new StudentDaoImpl();

    public void  doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		this.doPost(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		//获取模糊查询的请求参数
		String stId = request.getParameter("searchId");
		String stName = request.getParameter("searchname");
		String stSex = request.getParameter("searchsex");
		String stAge = request.getParameter("searchage");
		String stTel = request.getParameter("searchphone");
		String stDept = request.getParameter("searchdepartment");
		String stAddress = request.getParameter("searchsite");
		System.out.println(stId);
		//把请求参数封装为一个 CriteriaCustomer 对象
		CriteriaStudent cc = new CriteriaStudent(stId,stName,stSex,stAge,stTel,stDept,stAddress);
		
		//1. 调用 CustomerDAO 的 getForListWithCriteriaCustomer() 得到 Customer 的集合
		List<Student> students = StudentDao.getForListWithCriteriaStudent(cc);
		//2. 把 students 的集合放入 request 中
		request.setAttribute("students", students);
		request.getRequestDispatcher("/Search.jsp").forward(request, response);
		
//        String mainPage = "showstudent.jsp";
//		 request.setAttribute("mainPage", mainPage);
//		 RequestDispatcher dispatcher = request.getRequestDispatcher("Search.jsp");
//		 dispatcher.forward(request, response);
	}

}
